package com.example.demo.listener;

import com.alibaba.excel.context.AnalysisContext;
import com.alibaba.excel.event.AnalysisEventListener;
import com.example.demo.entity.DaAn;
import com.example.demo.service.DaAnService;

import java.util.ArrayList;
import java.util.List;

public class DaAnExcelListener extends AnalysisEventListener<DaAn> {
    private List<DaAn> data = new ArrayList<>();
    private DaAnService daAnService;

    public DaAnExcelListener(DaAnService daAnService) {
        this.daAnService = daAnService;
    }

    @Override
    public void invoke(DaAn daAn, AnalysisContext analysisContext) {

        data.add(daAn);
    }

    @Override
    public void doAfterAllAnalysed(AnalysisContext analysisContext) {
        System.out.println(data);
        if(daAnService != null){
            daAnService.insert(data);
        }
    }
}
